package ua.zwpp.java8.lambdas;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Created by vitaly on 16.09.14.
 *
 * Cheatsheet at http://www.java8.org/
 */
public class Demo {

    public static void main(String[] args) {
        Demo d = new Demo();
        d.case1();
        d.case2();
        d.case3();
        d.case4();
    }

    private void case1() {
        new Thread(() -> System.out.println("Hello, Lambda!")).start();
    }

    private void case2() {
        List<String> listToSort = Arrays.asList("Scala", "C++", "Java", "Clojure", "F#");

        Collections.sort(listToSort, (a, b) -> Integer.compare(a.length(), b.length()));

        System.out.println(listToSort);
    }

    private void case3() {
        List<String> strings = Arrays.asList("a", "b", "c");

        String prefix = "test_"; // effectively final
        strings.forEach(s -> System.out.println(prefix + s)); // see no parentheses around parameter s
    }

    private void case4() {
        // Diff from anon class in treatment of this
        new Thread(() -> System.out.println("this is " + this.getClass().getSimpleName())).start();
    }
}
